<template>
  <div>
    <van-nav-bar title="地址编辑"
                 left-text="返回"
                 left-arrow />
    <van-address-edit :area-list="areaList"
                      show-postal
                      show-delete
                      :address-info="addObj"
                      show-set-default
                      :area-columns-placeholder="['请选择', '请选择', '请选择']"
                      @save="onSave"
                      @delete="onDelete"
                      @change-detail="onChangeDetail" />
  </div>
</template>
<script>
import { addAddressApi, delAddressApi } from '../../api/address'
import areaList from '../../utils/area'
export default {
  data () {
    return {
      areaList: areaList,
      addressid: "",//修改和删除使用地址id 
      addObj: {
        addressDetail: "",
        name: "",
        tel: ""
      }
    }
  },
  created () {
    this.addObj.addressDetail = this.$route.params.addObj.address;
    this.addObj.name = this.$route.params.addObj.name;
    this.addObj.tel = this.$route.params.addObj.phone;
    this.addressid = this.$route.params.addObj.id;

  },
  methods: {
    async onSave (item) {//新增或编辑
      console.log(item)
      var res = await addAddressApi({
        uid: "956519",
        consignee: item.name,
        province: 10,
        city: 1002,
        county: "",
        tel: "",
        postalcode: item.postalCode,
        def: item.isDefault ? 1 : 0,
        phone: item.tel,
        address: item.addressDetail,
        raid: this.addressid  //地址id
      })
      console.log(res)
      this.$router.push({ name: "addressList" })
    },
    async onDelete () {  //地址删除
      var res = await delAddressApi(this.addressid)
      console.log(res)
      this.$router.push({ name: "addressList" })
    },
    onChangeDetail () { }
  }
}
</script>
<style lang="less">
</style>